<?php

#include
include "../site_specific/project.php";
include "../includes/constants.php";
include "../site_specific/external_constants.php";
include "../includes/phpmailer/class.phpmailer.php";
include "../includes/phpmailer/class.smtp.php";
include "../includes/utilities.php";
include "../includes/pages.php";
include "../includes/database.php";
include "../includes/users.php";
include "../includes/date.php";
include "../includes/text.php";
include "../includes/files.php";
include "../includes/tableproperties.php";

# Establish database connection
establishDatabaseConnection();



//$sql = "SELECT * FROM " . $PROJECT_DB_TABLES["glossary"] . " order by gl_letter";

//$result = getRecord($sql);

$output = "";

$selected_value=$_GET["value"];

$selected_mode=$_GET["mode"];

if($selected_mode!='ini'){
	
	//Letter has been selected
	if($selected_mode=='letter'){
		
		$sql = "SELECT * FROM " . $PROJECT_DB_TABLES["glossary"] . " WHERE gl_letter=\"".$selected_value."\" order by gl_term";

		$result = getRecord($sql);
		
		$index = 0;
		
		$id = '';
		
		foreach($result as $key => $value){
			
			if($index!=0){
				
				$pre_index = $index - 1;
				
				if($value['gl_term']==$result[$pre_index]['gl_term']){
				  
					$id = 'b_'.$value['gl_term']."_".$index;
				  
				}
				
				else{
					
					$id = 'b_'.$value['gl_term'];
				}
			  
			}
			else{
				
				$id = 'b_'.$value['gl_term'];
			}
			
			$id = str_replace("'","",$id);
			
			$output.="<a id='".$id."' onmouseout=\"MouseOverTerm('".$id."')\" onmouseover=\"openGlossaryDescription('".Encoding($value['gl_descripto'])."','G_DISCRO','".$id."')\" href=\"javascript:openGlossaryDescription('".Encoding($value['gl_descripto'])."','G_DISCRO','".$id."')\">".$value['gl_term']."</a>";
		
			//$output.="<br/>";	
			
			$index++;
		}
	}
	
	//Term has been chosen
	else if($selected_mode=='term'){
		
		$output .= replaceMessyCode($selected_value);
		
		//$sql = "SELECT * FROM " . $PROJECT_DB_TABLES["glossary"] . " WHERE gl_term=\"".$selected_value."\"";

		//$result = getRecord($sql);
		
		//$output.=$result[0]['gl_descripto'];
	}
	
}
else{
	
	$output.="<div id=\"G_Letters\">";
	
	$letters = array('Symbol','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
	
	foreach($letters as $key => $value){
		
		if($value != 'Symbol'){
		
			$image = "<img id=\"img_".$value."\" src=\"../site_specific/assets/images/letters/green_".strtolower($value).".png\" border=\"0\"/>";
		}
		else{
			$image = "<img id=\"word_".$value."\" src=\"../site_specific/assets/images/letters/green_symbol.png\" border=\"0\"/>";
			$image .= "<img id=\"img_".$value."\" src=\"../site_specific/assets/images/letters/green_blank.png\" border=\"0\"/>";
		}
		
		$output.="<a href=\"javascript:OpenGlossary('letter','".$value."')\" id='".$value."' >".$image."</a>";
		
		$output.="&nbsp;";
		
	}
	
	$output.="</div>";
	
	$output.="<div id=\"G_Terms\">";
	
	$output.="</div>";
	
	$output.="<div id=\"G_DISCRO\">";
	
	$output.="</div>";
}

echo $output;

?>